package com.hospital.diagnosis.module.hanlder;

import com.hospital.diagnosis.module.exception.DashScopeException;
import com.hospital.diagnosis.module.exception.enums.DashScopeExpCode;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.client.ResponseErrorHandler;

import java.io.IOException;

/**
 * DashScope构建错误处理器
 */
@Component
public class DashScopeErrorHandler implements ResponseErrorHandler {
    @Override
    public boolean hasError(ClientHttpResponse response) throws IOException {
        return response.getStatusCode().isError();
    }

    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
        throw new DashScopeException(DashScopeExpCode.DASH_SCOPE_API_ERROR);
    }
}
